package org.example.coursemangementserver.server.mapper;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.example.coursemangementserver.pojo.entity.Enrollment;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.example.coursemangementserver.pojo.vo.course.EnrollmentList.EnrollmentVO;
import org.example.coursemangementserver.pojo.vo.course.SelectCourseStatistics.SelectCourseStatisticVO;
import org.example.coursemangementserver.pojo.vo.course.StudentSelectCourseList.StudentSelectCourseVO;

import java.util.List;

/**
* @author 12438
* @description 针对表【enrollment(待选课程信息表)】的数据库操作Mapper
* @createDate 2024-06-18 19:22:20
* @Entity org.example.coursemangementserver.pojo.entity.Enrollment
*/
public interface EnrollmentMapper extends BaseMapper<Enrollment> {

    /**
     * 获取选课信息总数
     * @param name
     * @return
     */
    Integer getEnrollmentTotal(@Param("name")String name,@Param("teacherName") String teacherName);

    /**
     * 获取所有正常选课信息
     * @param start
     * @param pageSize
     * @param name
     * @return
     */
    List<EnrollmentVO> getEnrollmentList(@Param("start")Integer start, @Param("pageSize")Integer pageSize, @Param("name")String name, @Param("teacherName") String teacherName);

    /**
     * 获取某个学生的总的可选课程总数
     * @param grade 课程的年级
     * @param name 课程的名称
     * @param teacherName  老师姓名
     * @return
     */
    Integer getStudentSelectCourseTotal(@Param("studentId")Long studentId, @Param("grade") Integer grade, @Param("name") String name, @Param("teacherName") String teacherName);

    /**
     * 获取某个学生的所有可选信息
     * @param start
     * @param pageSize
     * @param grade
     * @param name
     * @param teacherName
     * @return
     */
    List<StudentSelectCourseVO> getStudentSelectCourseList(@Param("studentId")Long studentId,@Param("start") Integer start, @Param("pageSize") Integer pageSize, @Param("grade") Integer grade, @Param("name") String name, @Param("teacherName") String teacherName);

    @Select("select * from enrollment where enrollment_id = #{enrollmentId}")
    Enrollment getEnrollmentById(Long enrollmentId);

    List<SelectCourseStatisticVO> getSelectCourseStatistics();

    // 更新选课状态为"选课结束"
    @Update("UPDATE enrollment SET status = 2 WHERE stop_time < NOW() AND status = 1")
    void updateStatusToFinished();

    Enrollment getEnrollmentByCondition(@Param("teacherId") Long teacherId, @Param("onClass") Integer onClass, @Param("week") Integer week);
}




